<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="用户名称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名称"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入手机号码"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺名称" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺编号" prop="shopNo">
        <el-input
          v-model="queryParams.shopNo"
          placeholder="请输入店铺编号"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编号"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="套餐名" prop="packageName">
        <el-input
          v-model="queryParams.packageName"
          placeholder="请输入套餐名"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="领取日期" prop="date">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          unlink-panels
          value-format="YYYY-MM-DD"
          format="YYYY-MM-DD"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :shortcuts="shortcuts"
          :size="size"
          @change="changeDate"
        />
      </el-form-item>
      <el-form-item label="订单创建时间（达成）" label-width="160" prop="date1">
        <el-date-picker
          v-model="dateRange1"
          type="daterange"
          unlink-panels
          value-format="YYYY-MM-DD"
          format="YYYY-MM-DD"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :shortcuts="shortcuts"
          :size="size"
          @change="changeDate1"
        />
      </el-form-item>
      <el-form-item label="充值状态" prop="status">
        <el-select
          v-model="queryParams.status"
          clearable
          filterable
          placeholder="请选择状态"
          style="width: 100%"
        >
          <el-option :key="0" label="失败" value="0" />
          <el-option :key="1" label="充值中" value="1" />
          <el-option :key="2" label="充值成功" value="2" />
          <el-option :key="3" label="失败已退款" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否计算数据" prop="isCount" label-width="100">
        <el-select
          v-model="queryParams.isCount"
          clearable
          filterable
          placeholder="请选择状态"
          style="width: 100%"
        >
          <el-option :key="0" label="否" value="否" />
          <el-option :key="0" label="是" value="是" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['phoneBill:receive:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="Ticket"
          @click="handleIndoor"
          v-hasPermi="['phoneBill:receive:indoor']"
          >话费后台补领</el-button
        >
      </el-col>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
        :columns="columns"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="userList"
      @selection-change="handleSelectionChange"
      border
    >
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column
        label="领取时间"
        align="center"
        key="createTime"
        prop="createTime"
        v-if="columns[0].visible"
        width="100"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="领取成功时间" align="center" key="createSucTime" prop="createSucTime"
        v-if="columns[10].visible">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="套餐名称"
        align="center"
        key="packageName"
        prop="packageName"
        v-if="columns[1].visible"
        :show-overflow-tooltip="true"
        width="100"
      />
      <el-table-column
        label="订单编号"
        align="center"
        key="orderNo"
        prop="orderNo"
        v-if="columns[2].visible"
        width="100"
      />
      <el-table-column
        label="店铺名称"
        align="center"
        key="shopName"
        prop="shopName"
        v-if="columns[3].visible"
        width="100"
      />
      <el-table-column
        label="店铺编号"
        align="center"
        key="shopNo"
        prop="shopNo"
        v-if="columns[4].visible"
        width="100"
      />
      <el-table-column
        label="手机号码"
        align="center"
        key="phoneNumber"
        prop="phoneNumber"
        v-if="columns[5].visible"
        width="100"
      />
      <el-table-column
        label="用户名称"
        align="center"
        key="userName"
        prop="userName"
        v-if="columns[6].visible"
        width="100"
      />

      <el-table-column
        label="领取金额"
        align="center"
        key="receiveAmount"
        prop="receiveAmount"
        v-if="columns[7].visible"
        width="100"
      />

      <el-table-column
        label="实扣金额"
        align="center"
        key="actualAmount"
        prop="actualAmount"
        v-if="columns[9].visible"
        width="100"
      />
      <el-table-column
        label="领取类型"
        align="center"
        key="receiveType"
        prop="receiveType"
        width="100"
      />
      <el-table-column
        label="领取备注"
        align="center"
        key="var2"
        prop="var2"
        width="100"
      />
      <el-table-column
        label="内部领取备注"
        align="center"
        key="receiveRemark"
        prop="receiveRemark"
        width="120"
      />
      <el-table-column
        label="领取所属月份"
        align="center"
        key="getDate"
        prop="getDate"
        v-if="columns[14].visible"
        width="100"
      >
      </el-table-column>
      <el-table-column
        label="上级名称"
        align="center"
        key="superName"
        prop="superName"
        v-hasPermi="['phoneBill:receive:super']"
        width="100"
      >
      </el-table-column>

      <el-table-column
        label="状态"
        align="center"
        key="status"
        prop="status"
        v-if="columns[8].visible"
        width="100"
      >
        <template #default="scope">
          <span v-if="scope.row.status == 0"> 失败 </span>
          <span v-if="scope.row.status == 1"> 充值中 </span>
          <span v-if="scope.row.status == 2"> 充值成功 </span>
          <span v-if="scope.row.status == 3"> 失败已退款 </span>
        </template>
      </el-table-column>
      <el-table-column
        label="重推状态"
        align="center"
        key="againStatus"
        prop="againStatus"
        v-if="columns[15].visible"
        width="100"
      />
      <el-table-column
        label="手动充值状态"
        align="center"
        key="labourStatus"
        prop="labourStatus"
        v-if="columns[11].visible"
        width="100"
      >
        <template #default="scope">
          <span v-if="scope.row.labourStatus == 0"> 失败 </span>
          <span v-if="scope.row.labourStatus == 1"> 充值中 </span>
          <span v-if="scope.row.labourStatus == 2"> 充值成功 </span>
          <span v-if="scope.row.labourStatus == 3"> 失败已退款 </span>
        </template>
      </el-table-column>
      <el-table-column
        label="手动充值时间"
        align="center"
        key="labourTime"
        prop="labourTime"
        v-if="columns[13].visible"
        width="100"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.labourTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="手动充值备注"
        align="center"
        key="labourRemark"
        prop="labourRemark"
        v-if="columns[12].visible"
        width="100"
      />
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        width="120"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-link
            :disabled="
              (scope.row.status != 0 && scope.row.status != 3) ||
              scope.row.againStatus === '重推下单成功' ||
              scope.row.againStatus === '重推充值成功' ||
              scope.row.againStatus === '重推充值中' ||
              scope.row.labourStatus != null
            "
            type="primary"
            @click="againPush(scope.row)"
            >重推</el-link
          >
          <el-link
            type="primary"
            style="margin: 0 10px"
            @click="againPushRe(scope.row)"
            >重推记录</el-link
          >
          <!-- <el-button link type="primary" @click="handleSee(scope.row)"
            v-hasPermi="['phoneBill:receive:query']">查看详情</el-button> -->
          <el-button
            link
            type="primary"
            @click="handlManual(scope.row)"
            v-hasPermi="['phoneBill:receive:manual']"
            >手动更新</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 重推记录 -->
    <el-dialog title="重推记录" v-model="open1" width="80%" append-to-body>
      <el-table v-loading="loading" :data="againList">
        <el-table-column
          label="ID"
          align="center"
          key="id"
          prop="id"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="推送时间"
          align="center"
          key="createTime"
          prop="createTime"
        >
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单编号"
          align="center"
          key="orderNo"
          prop="orderNo"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="用户名称"
          align="center"
          key="userName"
          prop="userName"
          width="120"
        />

        <el-table-column
          label="状态"
          align="center"
          key="status"
          prop="status"
          width="160"
        >
        </el-table-column>
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="open1 = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 话费补领弹窗 -->
    <el-dialog
      title="话费补领内部通道"
      v-model="BlFlag"
      width="600px"
      append-to-body
      @close="restBl"
    >
      <el-form :rules="blRules" :model="BLForm" ref="blRef" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="username">
              <el-input
                v-model="BLForm.username"
                maxlength="15"
                @blur="checkAndGetReceiveInfo"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号" prop="phone">
              <el-input
                v-model="BLForm.phone"
                maxlength="11"
                @blur="checkAndGetReceiveInfo"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item style="margin-left: -70px">
              <el-button @click="orderSearch" type="success"
                >查询充值记录</el-button
              >
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="领取备注" prop="receiveRemark">
              <el-select
                v-model="BLForm.receiveRemark"
                clearable
                filterable
                placeholder="请选择状态"
                style="width: 100%"
              >
                <el-option :key="0" label="未结佣" value="未结佣" />
                <el-option :key="1" label="过期无法领取" value="过期无法领取" />
                <el-option
                  :key="2"
                  label="担心验证码不安全"
                  value="担心验证码不安全 "
                />
                <el-option :key="3" label="老人不会操作" value="老人不会操作" />
                <el-option :key="4" label="收不到验证码" value="收不到验证码" />
                <el-option :key="5" label="欠费提前领取" value="欠费提前领取" />
                <el-option :key="6" label="投诉提前领取" value="投诉提前领取" />
                <el-option :key="7" label="客户不愿操作" value="客户不愿操作" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="blSure" type="primary">确 定</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 手动更新 -->
    <el-dialog
      title="手动更新"
      v-model="manualDialog"
      width="600px"
      append-to-body
      @close="cancelMu"
    >
      <el-form
        :model="manuaForm"
        :rules="manuaRules"
        ref="manuaRef"
        label-width="80px"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="充值ID" prop="phoneBillId">
              <el-input v-model="manuaForm.phoneBillId" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="充值状态" prop="labourStatus">
              <el-select
                v-model="manuaForm.labourStatus"
                clearable
                filterable
                placeholder="请选择状态"
                style="width: 100%"
                disabled
              >
                <el-option :key="0" label="失败" value="0" />
                <el-option :key="1" label="充值中" value="1" />
                <el-option :key="2" label="充值成功" value="2" />
                <el-option :key="3" label="失败已退款" value="3" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="labourRemark">
              <el-input v-model="manuaForm.labourRemark" type="textarea" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注图片" prop="file">
              <el-upload
                list-type="picture-card"
                ref="uploadRef"
                :limit="1"
                :file-list="fileList"
                :show-file-list="true"
                :headers="upload.headers"
                :action="upload.url"
                accept="image/*"
                :on-success="handleFileSuccess"
                :on-change="handleChageImg1"
                :auto-upload="true"
              >
                <el-icon>
                  <Plus />
                </el-icon>

                <template #file="{ file }">
                  <div>
                    <img
                      class="el-upload-list__item-thumbnail"
                      :src="file.url"
                      alt=""
                    />
                    <span class="el-upload-list__item-actions">
                      <span
                        class="el-upload-list__item-preview"
                        @click="handlePictureCardPreview(file)"
                      >
                        <el-icon><zoom-in /></el-icon>
                      </span>
                      <span
                        v-if="!disabled"
                        class="el-upload-list__item-delete"
                        @click="handleRemove(file)"
                      >
                        <el-icon>
                          <Delete />
                        </el-icon>
                      </span>
                    </span>
                  </div>
                </template>
              </el-upload>

              <el-dialog v-model="dialogVisible" width="50%">
                <img :src="dialogImageUrl" alt="Preview Image" class="img" />
              </el-dialog>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancelMu">取 消</el-button>
          <el-button @click="handleManua" type="primary">确 定 </el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 充值/领取记录 -->
    <el-dialog
      title="返费记录"
      v-model="open3"
      width="100%"
      append-to-body
      v-loading="loading"
    >
      <el-row :gutter="20">
        <el-col :span="13">
          <h4>达成充值记录(金额：{{ dc }})</h4>
          <el-table v-loading="loading" :data="recList">
            <el-table-column
              label="充值时间"
              align="center"
              key="date"
              prop="date"
              width="180"
            >
              <template #default="scope">
                <span>{{ parseTime(scope.row.date) }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="账户名"
              align="center"
              key="userName"
              prop="userName"
            />
            <el-table-column
              label="手机号"
              align="center"
              key="phone"
              prop="phone"
            />
            <el-table-column
              label="充值金额"
              align="center"
              key="amount"
              prop="amount"
            />
            <el-table-column
              label="实扣金额"
              align="center"
              key="realityAmount"
              prop="realityAmount"
            />
            <el-table-column label="充值状态" align="center" key="state"
              >充值成功</el-table-column
            >
            <el-table-column
              label="佣金状态"
              align="center"
              key="commissionState"
              prop="commissionState"
            />
          </el-table>
        </el-col>
        <el-col :span="11">
          <h4>达成2.0用户领取记录(金额：{{ dc2 }})</h4>
          <el-table v-loading="loading" :data="recList1">
            <el-table-column
              label="领取时间"
              align="center"
              key="date"
              prop="date"
              width="180"
            >
              <template #default="scope">
                <span>{{ parseTime(scope.row.date) }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="手机号"
              align="center"
              key="phone"
              prop="phone"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="领取金额"
              align="center"
              key="amount"
              prop="amount"
            />
            <el-table-column
              label="实扣金额"
              align="center"
              key="realityAmount"
              prop="realityAmount"
            />
            <el-table-column label="领取状态" align="center" key="state"
              >领取成功</el-table-column
            >
          </el-table>
        </el-col>
      </el-row>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="open3 = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Receive">
import { getToken } from "@/utils/auth";
import {
  listReceive,
  InfoRechargeOrder,
  againPushEffect,
  getAgainRe,
  indoor,
  manual,
  recListApi,
  receiveInfoFnc,
} from "@/api/phoneBill/receive";
import { ElMessage } from "element-plus";
import { reactive } from "vue";
import { parseTime } from "@/utils/ruoyi.js";
import { shortcuts, Y, M, D } from "@/utils/dateSet";

const { proxy } = getCurrentInstance();
const open1 = ref(false);
const userList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const dateRange = ref([
  parseTime(
    new Date(Y.value, M.value, D.value, 0, 0, 0).getTime() -
      3600 * 1000 * 24 * 30
  ),
  parseTime(new Date(Y.value, M.value, D.value, 23, 59, 59).getTime()),
]);
const dateRange1 = ref([]);

// 列显隐信息
const columns = ref([
  { key: 0, label: `领取时间`, visible: true },
  { key: 1, label: `套餐名称`, visible: true },
  { key: 2, label: `订单编号`, visible: true },
  { key: 3, label: `店铺名称`, visible: true },
  { key: 4, label: `店铺编号`, visible: true },
  { key: 5, label: `手机号码`, visible: true },
  { key: 6, label: `用户名称`, visible: true },
  { key: 7, label: `领取金额`, visible: true },
  { key: 9, label: `实扣金额`, visible: true },
  { key: 8, label: `状态`, visible: true },
  { key: 10, label: `领取成功时间`, visible: true },
  { key: 11, label: `手动充值状态`, visible: true },
  { key: 12, label: `手动充值备注`, visible: true },
  { key: 13, label: `手动充值时间`, visible: true },
  { key: 14, label: `领取所属月份`, visible: true },
  { key: 15, label: `重推状态`, visible: true },
]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    userName: undefined,
    phoneNumber: undefined,
    status: undefined,
    deptId: undefined,
    isCount: undefined,
  },
  rules: {
    userName: [
      { required: true, message: "用户名称不能为空", trigger: "blur" },
      {
        min: 2,
        max: 20,
        message: "用户名称长度必须介于 2 和 20 之间",
        trigger: "blur",
      },
    ],
    nickName: [
      { required: true, message: "用户昵称不能为空", trigger: "blur" },
    ],
    password: [
      { required: true, message: "用户密码不能为空", trigger: "blur" },
      {
        min: 5,
        max: 20,
        message: "用户密码长度必须介于 5 和 20 之间",
        trigger: "blur",
      },
    ],
    email: [
      {
        type: "email",
        message: "请输入正确的邮箱地址",
        trigger: ["blur", "change"],
      },
    ],
    phoneNumber: [
      {
        pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
        message: "请输入正确的手机号码",
        trigger: "blur",
      },
    ],
  },
  blRules: {
    username: [
      { required: true, message: "用户名称不能为空", trigger: "blur" },
    ],
    phone: [{ required: true, message: "手机号不能为空", trigger: "blur" }],
  },
  manuaRules: {
    labourStatus: [
      { required: true, message: "充值状态不能为空", trigger: "blur" },
    ],
  },
});

const { queryParams, form, rules, blRules, manuaRules } = toRefs(data);
const changeDate = (val) => {
  if (!val) {
    dateRange.value = [];
  } else {
    queryParams.value.start = dateRange.value[0];
    queryParams.value.end = dateRange.value[1];
  }
};
const changeDate1 = (val) => {
  if (!val) {
    dateRange1.value = [];
  } else {
    queryParams.value.orderStart = dateRange1.value[0];
    queryParams.value.orderEnd = dateRange1.value[1];
  }
};
/** 查询用户列表 */
function getList() {
  loading.value = true;
  listReceive(
    proxy.addDateRange({
      ...queryParams.value,
      start: dateRange.value ? dateRange.value[0] : "",
      end: dateRange.value ? dateRange.value[1] : "",
      orderStart: dateRange1.value ? dateRange1.value[0] : "",
      orderEnd: dateRange1.value ? dateRange1.value[1] : "",
    })
  ).then((res) => {
    loading.value = false;
    userList.value = res.rows;
    total.value = res.total;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [
    parseTime(
      new Date(Y.value, M.value, D.value).getTime() - 3600 * 1000 * 24 * 30
    ),
    parseTime(new Date(Y.value, M.value, D.value, 23, 59, 59).getTime()),
  ];
  dateRange1.value = [];
  proxy.resetForm("queryRef");
  queryParams.value.deptId = undefined;
  queryParams.value.start = dateRange.value[0];
  queryParams.value.end = dateRange.value[1];
  queryParams.value.orderStart = "";
  queryParams.value.orderEnd = "";
  // proxy.$refs.deptTreeRef.setCurrentKey(null);
  handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "system/receive/export",
    {
      ...queryParams.value,
      start: dateRange.value ? dateRange.value[0] : "",
      end: dateRange.value ? dateRange.value[1] : "",
      orderStart: dateRange1.value ? dateRange1.value[0] : "",
      orderEnd: dateRange1.value ? dateRange1.value[1] : "",
    },
    `领取记录${new Date().getTime()}.xlsx`
  );
}

/**话费内部补领 */
const BlFlag = ref(false);
const BLForm = reactive({
  phone: "",
  username: "",
  receiveRemark: "",
});
function handleIndoor() {
  BlFlag.value = true;
}
function blSure() {
  proxy.$refs["blRef"].validate((valid) => {
    if (valid) {
      indoor({
        phone: BLForm.phone,
        username: BLForm.username,
        receiveRemark: BLForm.receiveRemark,
      }).then((res) => {
        if (res.code == 200) {
          BlFlag.value = false;
          ElMessage.success("充值成功");
        } else {
          ElMessage.error(res.msg);
        }
      });
    }
  });
}
// 领取信息
// 检查并获取领取信息
function checkAndGetReceiveInfo() {
  // 当用户名和手机号都有值时调用getReceiveInfo方法
  if (BLForm.username && BLForm.phone) {
    getReceiveInfo();
  }
}

function getReceiveInfo() {
  receiveInfoFnc({
    phone: BLForm.phone,
    username: BLForm.username,
  }).then((res) => {
    if (res.code == 200) {
      console.log(res);
    } else {
      ElMessage.error(res.msg);
    }
  });
}

function restBl() {
  BLForm.phone = "";
  BLForm.username = "";
  BLForm.receiveRemark = "";
}
/**E N D */

/** 选择条数  */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.userId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 重置操作表单 */
function reset() {
  form.value = {};
  proxy.resetForm("userRef");
}
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

//查看详情
// function handleSee(row) {
//   reset();
//   const id = row?.phoneBillId;
//   InfoRechargeOrder(id).then((response) => {
//     form.value = response.data;
//     open.value = true;
//     title.value = "详情";
//   });
// }

//重新推送
const againPush = (row) => {
  againPushEffect({
    phoneNumber: row.phoneNumber,
    id: row.id,
    phoneBillId: row.phoneBillId,
    receiveAmount: row.receiveAmount,
    userName: row.userName,
    getDate: row.getDate,
  }).then((res) => {
    // console.log(res);
    if (res.code == 200) {
      ElMessage.success(res.msg);
      getList();
    }
  });
};

//重推记录
const againList = ref([]);
const againPushRe = (row) => {
  open1.value = true;
  getAgainRe({
    id: row.id,
  }).then((res) => {
    console.log(res);
    if (res.code == 200) {
      againList.value = res.rows;
    }
  });
};

/**手动更新 */
const manuaForm = reactive({
  labourStatus: "2",
  labourRemark: "",
  phoneBillId: "",
  labourImgPath: "",
});
const fileList = ref([]); /**图片列表 */
const dialogImageUrl = ref("");
const dialogVisible = ref(false);
const manualDialog = ref(false);
const disabled = ref(false);
const upload = reactive({
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken() },
  //上传地址
  url: import.meta.env.VITE_APP_BASE_API + "/common/upload",
});
const handleChageImg1 = (file, resfileList) => {
  const size = ref(5);
  const fileSizeFlag = file.size / 1024 / 1024 < size.value;
  if (!fileSizeFlag) {
    ElMessage.error(`请上传不大于${size.value}M的图片!`);
    fileList.value = [];
  } else {
    fileList.value = resfileList;
  }
};

const handleRemove = (file) => {
  proxy.$refs["uploadRef"].handleRemove(file);
  manuaForm.labourImgPath = "";
};

const handlePictureCardPreview = (file) => {
  dialogImageUrl.value = file.url;
  dialogVisible.value = true;
};
const handleFileSuccess = (response, file, fileList) => {
  // console.log(response, "09211as");
  manuaForm.labourImgPath =
    import.meta.env.VITE_APP_BASE_API + response.fileName;
};
const handlManual = (row) => {
  manualDialog.value = true;
  manuaForm.labourStatus = "2";
  // manuaForm.labourImgPath = row.labourImgPath
  if (row.labourImgPath) {
    fileList.value = row.labourImgPath?.split(",").map((item) => {
      return {
        url: `${item}`,
      };
    });
  }
  manuaForm.phoneBillId = row.phoneBillId;
  manuaForm.labourRemark = row.labourRemark;
};
const handleManua = () => {
  // console.log(manuaForm)
  // return
  manual({
    labourStatus: manuaForm.labourStatus,
    labourImgPath: manuaForm.labourImgPath,
    phoneBillId: manuaForm.phoneBillId,
    labourRemark: manuaForm.labourRemark,
  }).then((res) => {
    // console.log(res);
    if (res.code == 200) {
      ElMessage.success(res.msg);
      manualDialog.value = false;
      getList();
    }
  });
};
const cancelMu = () => {
  manualDialog.value = false;
  manuaForm.labourStatus = "2";
  manuaForm.labourImgPath = "";
  manuaForm.phoneBillId = "";
  manuaForm.labourRemark = "";
  fileList.value = [];
};
getList();
/**话费领取记录 */
//充值记录查询
const open3 = ref(false);
const recList = ref([]);
const recList1 = ref([]);
const dc = ref("");
const dc2 = ref("");
const orderSearch = () => {
  if (!BLForm.phone) return ElMessage.error("请填写手机号后查询！");
  open3.value = true;
  loading.value = true;
  recListApi({ phoneNumber: BLForm.phone }).then((res) => {
    console.log(res);
    dc.value = res.data.directCharge;
    dc2.value = res.data.manualPickup;
    recList.value = res.data.numberList;
    recList1.value = res.data.numberLists;
    loading.value = false;
  });
};
</script>
